package com.semp.jadoma.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;

import com.semp.jadoma.core.model.Family;
import com.semp.jadoma.web.bean.FamilyBean;
import com.semp.jadoma.web.form.FamilyDisplayForm;
import com.semp.jadoma.web.utils.webapp.Forward;
import com.semp.jadoma.web.utils.webapp.Session;

public class FamilyDisplayAction extends RootAction {

	@Override
	public String executeChild(ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		/*
		 * Find the family
		 */
		FamilyDisplayForm familyDisplayForm = (FamilyDisplayForm) form;
		Family family = familyService.getFamily(familyDisplayForm.getFamilyId());
		
		if (family == null) {
			/*
			 * No family found
			 */
			return Forward.FAILURE;
		} else {
			/*
			 * Store family bean in request
			 */
			request.setAttribute(Session.BEAN_FAMILY, new FamilyBean(family));
			return Forward.SUCCESS;
		}
	}

}
